package testcase.app;

import org.json.JSONObject;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import api.app.GetVerificationCode;
import common.Host;
import common.TestData;

/**
 * 帮忙医APP用户注册获取验证码TestGetVerificationCode接口测试用例
 * 
 * @author WuZF
 *
 */
public class TestGetVerificationCode
{
	/**
	 * 帮忙医APP用户注册获取验证码TestGetVerificationCode接口测试环境数据驱动
	 * 
	 * @return
	 * @throws Exception
	 */
	@DataProvider(name = "Test")
	public static String[][] testGetVerificationCodeDataProvider() throws Exception
	{
		Host.setup("Test");
		TestData td = new TestData("app/TestGetVerificationCode.xml");
		return td.getParam();
	}

	/**
	 * 帮忙医APP用户注册获取验证码TestGetVerificationCode接口测试用例
	 * 
	 * @param casename
	 *            用例名称
	 * @param telephone
	 *            手机号
	 * @throws Exception
	 */
	@Test(dataProvider = "Test", groups = { "Test" })
	public void testGetVerificationCodeTestCase(String casename, String telephone) throws Exception
	{
		// 调用接口并将接口返回数据转换成json格式
		String result = GetVerificationCode.post(telephone);
		JSONObject jsonResult;
		if (result== null || result.isEmpty())
		{
			jsonResult = null;
		}
		else
		{
			jsonResult = new JSONObject(result);
		}

		// 设置检查点
		switch (casename)
		{
			case "Registered":
				Assert.assertTrue(jsonResult.getJSONObject("Data").getBoolean("MobileExist"));
				break;
			case "UnRegistered":
				Assert.assertFalse(jsonResult.getJSONObject("Data").getBoolean("MobileExist"));
				break;
			case "ShortTelephone":
				Assert.assertFalse(jsonResult.getJSONObject("Data").getBoolean("MobileExist"));
				break;
			case "LongTelephone":
				Assert.assertFalse(jsonResult.getJSONObject("Data").getBoolean("MobileExist"));
				break;
			case "ErrorTelephone":
				Assert.assertFalse(jsonResult.getJSONObject("Data").getBoolean("MobileExist"));
				break;
		}
	}
}
